<?php

use Hyperf\Database\Schema\Schema;
use Hyperf\Database\Schema\Blueprint;
use Hyperf\Database\Migrations\Migration;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('rd_message_read', function (Blueprint $table) {
            $table->comment('消息读取状态表');
            $table->bigIncrements('id')->comment('主键ID');
            $table->unsignedBigInteger('message_id')->comment('消息ID');
            $table->unsignedBigInteger('user_id')->comment('接收用户ID');
            $table->unsignedTinyInteger('status')->default(1)->comment('读取状态 1未读 2已读');
            $table->dateTime('read_time')->nullable()->comment('读取时间');
            $table->unsignedTinyInteger('type')->comment('消息类型');
            $table->datetimes();
            
            // 添加索引
            $table->index(['message_id', 'user_id'], 'idx_message_user');
            $table->index('user_id', 'idx_user');
            $table->index('status', 'idx_status');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('rd_message_read');
    }
};